package DVD;

/**
 * @(#)DVDStore.java
 *
 *
 * @Qiqa Kotyi(209030372)
 * 
 * @version 1.00 2012/5/7
 */
import DVD.Customer;
import DVD.DVD;
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.Date;

public class DVDStore extends JFrame implements ActionListener{


       DVD dvd1 = new DVD();

       Customer cust1  = new Customer();
       DVD[] dvdArray =  new DVD[10];
       Customer[] custArray =  new Customer[10];

       int cnt=7;
       int count=7;

       int custCount;
       int mvCount;

       double total1;
       double total2;
       //int cost = 10.0;
       String[] options1 = {"Select","true","false"};
       String[] options2 = {"Select","true","false"};
       String firstName;
       String surname;
       String phoneNum;
       double credit;

       String title;
       int category;
       boolean newRelease;
       boolean availableForRent;

       DVD dvd2 = new DVD(title,category,newRelease,availableForRent);
       Customer cust2  = new Customer(firstName,surname,phoneNum,credit);

       String [] categories = new String[8];

        /** Main Frame **/

        private JLabel picLabel ;
        private JLabel pic2Label = new JLabel() ;
        private JLabel pic3Label = new JLabel();
        private JLabel pic4Label = new JLabel();
        private JLabel pic5Label = new JLabel();
        private JLabel pic6Label = new JLabel("    "+"HEADLINES: 'BAD BUDDIES' Comedy movie by 'Leon Schuster' and "+"'Madea's Witness Protection' by Tyler Perry ,comming soon...");
        private JLabel pic7Label = new JLabel("Thank you for using Mr Video ,Call Again...");
        
        private JLabel timeLabel;

        private DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd  HH:mm:ss");
        private Date date = new Date();

        private JTextArea area =  new JTextArea(15,40);

        private JTextArea area2 =  new JTextArea(20,30);

        private JMenuBar menuBar =  new JMenuBar();
        private JMenu opMenu = new JMenu("Operation");
        private JMenu sysMenu = new JMenu("System");

        private JMenuItem addItem = new JMenuItem("Add New");
        private JMenuItem sortMvItem = new JMenuItem("Sort Movies");
        private JMenuItem custListItem = new JMenuItem("Customer List");
        private JMenuItem avlMvItem = new JMenuItem("Available Movies");
        private JMenuItem listMoviItem = new JMenuItem("List movies start with...");
        private JMenuItem exitItem = new JMenuItem("Exit");
        private JMenuItem abtItem = new JMenuItem("About");
        private JMenuItem rentItem = new JMenuItem("Rent Movie");
        private JMenuItem delItem = new JMenuItem("Delete Item");


        /** Icons */
        Icon addIcon= new ImageIcon("imagesCA33159U.jpg");
        Icon deleteIcon = new ImageIcon("DeleteRed.png");
        Icon sortImg = new ImageIcon("sort.jpg ");
        Icon availIcon= new ImageIcon("avail.jpg ");
        Icon exitIcon= new ImageIcon("exit.jpg ");
        Icon custIcon= new ImageIcon("cust.jpg ");
        Icon movieIcon= new ImageIcon("movies.jpg ");
        Icon rentIcon= new ImageIcon("rent.jpg ");

        /*** Buttons */
        private JButton addBtn = new JButton("Add New");
        private JButton delBtn = new JButton("Delete");
        private JButton listBtn = new JButton("Sort Movies");
        private JButton avlBtn = new JButton("Available Movies");
        private JButton custBtn = new JButton("Customer list");
        private JButton moviBtn = new JButton("List Movies Start with...");
        private JButton rentBtn = new JButton("Rent Movie");
        private JButton exitBtn = new JButton("Exit");

        private JPanel northPanel = new JPanel();
        private JPanel eastPanel = new JPanel();
        private JPanel southPanel = new JPanel();
        private JPanel westPanel = new JPanel();
        private JPanel centerPanel = new JPanel();
        private JLabel mainLabel = new JLabel();
        /** Rent JFrame */

        private JFrame rentFrame = new JFrame("Rent Movie");
        private JTextArea area3  =  new JTextArea(20,45);
         private JList moviList = new JList();
       // private Action selectLine;
        //JScrollPane scrollPane = new JScrollPane( area3 );

        private JLabel dum1Label = new JLabel();
        private JLabel dum2Label = new JLabel();
        private JLabel dum3Label = new JLabel();

        private JLabel numLabel = new JLabel("Phone number:");
        private JTextField numField = new JTextField(5);
        private JLabel tLabel = new JLabel("Movie title:");
        private JTextField titleField = new JTextField(5);


        private JLabel rentLabelPic;
        private JButton searcPhone =  new JButton("Search number");
        private JButton searcTitle =  new JButton("Search title");
        private JButton rntBtn =  new JButton("Rent");
        private JButton bckBtn =  new JButton("Back to Main");
        private JLabel instrLabel;

        private JLabel optionLB = new JLabel("Choose record to search:");


        private JPanel nrthPanel = new JPanel();
        private JPanel wstPanel = new JPanel();
        private JPanel estPanel = new JPanel();
        private JPanel sthPanel = new JPanel();
        private JPanel areaPanel = new JPanel();

        /** ADD JFrame **/
        private JFrame addFrame = new JFrame("Add Record");

        /**Radio Buttons*/

        private JLabel custLabel = new JLabel("Customer");

        private JRadioButton custRadio = new JRadioButton();

        private JLabel movLabel = new JLabel("Movie");

        private JRadioButton movRadio = new JRadioButton();
        /** Customer */
        private JLabel nameLabel = new JLabel("First name:");
        private JTextField nameText = new JTextField(5);
        private JLabel snameLabel = new JLabel("Last name:");
        private JTextField snameText = new JTextField(5);
        private JLabel phnLabel = new JLabel("Phone number:");
        private JTextField phnText = new JTextField(5);
        private JLabel creditLabel = new JLabel("Credit:");
        private JTextField creditText = new JTextField(5);

        /** Movie */
        private JLabel titleLabel = new JLabel("Title:");
        private JTextField titleText = new JTextField(5);
        private JLabel catLabel = new JLabel("Category:");
        private JComboBox catCombo;
        private JLabel newRLabel = new JLabel("New Release:");
        private JComboBox newRCombo;
        private JLabel availLabel = new JLabel("Available for rent:");
        private JComboBox availRCombo;
        
        private JButton insertCBtn =  new JButton("Insert customer");
        private JButton insertMBtn =  new JButton("Insert Movie");
        private JButton closeBtn =  new JButton("Back to Main");

        private JPanel nPanel = new JPanel();
        private JPanel ePanel = new JPanel();
        private JPanel sPanel = new JPanel();
        private JPanel wPanel = new JPanel();
        private JPanel cPanel = new JPanel();

        /** End of Movie **/

        /** Movies start with Frame*/
        private JFrame startFrame = new JFrame("Movies start with...");

        private JLabel strtLabel ;
        private JLabel strtFieldLabel = new JLabel("Fisrt title letter:");
        private JTextField serchField = new JTextField(5);
        private JTextArea startArea =  new JTextArea(20,40);
        private JButton startBtn =  new JButton("search");
        private JButton gobBtn =  new JButton("Back to main");
        private JPanel fieldPanel = new JPanel();
        private JPanel labelPanel = new JPanel();
        private JPanel startAreaPanel = new JPanel();
        private JPanel startBtnPanel = new JPanel();

        /** End of Movies start with Frame **/

        /*** Delete Frame */

        private JFrame delFrame = new JFrame("Delete");


        private JLabel delLabel; ///= new JLabel("PLEASE CHOOSE OPTION TO DELETE");

        private JLabel delPicLabel;
        private JLabel custDelLabel  = new JLabel("Phone number");
        private JTextField cutDelText = new JTextField(5);

        private JLabel mvDelLabel  = new JLabel("Moive title:");
        private JTextField mvDelText = new JTextField(5);

        private JButton deleteCBtn = new JButton("Delete Customer");
        private JButton deleteMBtn = new JButton("Delete Movie");

        private JButton toMainBtn = new JButton("Back To Main");
        private JPanel opPanel = new JPanel();
        private JPanel op2Panel = new JPanel();
        private JPanel topPanel = new JPanel();
        private JPanel btnPanel = new JPanel();
        private JPanel listPanel = new JPanel();


        /**End of Delete Frame */

        /** About Frame */

        private JFrame aboutFrame = new JFrame("ABOUT PROGRAMMERS");
        private JLabel proPic;
        private JLabel aboutPic;
        private JPanel progPanel = new JPanel();
        private JPanel namesPanel = new JPanel();

        private JLabel qiqaLabel = new JLabel("Qiqa Kotyi-Director & Programmer");
        private JLabel joeLabel = new JLabel("Josefa Mthombeni-Programmer");
        private JLabel lynxLabel = new JLabel("Lynx Feni-Programmer");
        private JPanel vidPanel = new JPanel();
        
        private JLabel abtPic1Label;
        private JLabel abtPic2Label;
        private JLabel abtPic3Label;
        /** end About Frame*/

        public DVDStore()
        {
                super("Movie Rental System");
                setLayout(new BorderLayout());


                /** Main frame menu */

                setJMenuBar(menuBar);
                menuBar.add(opMenu);
                menuBar.add(sysMenu);
                sysMenu.add(exitItem);
                sysMenu.add(abtItem);
                opMenu.add(addItem);
                opMenu.add(sortMvItem);
                opMenu.add(custListItem);
                opMenu.add(listMoviItem);
                opMenu.add(avlMvItem);
                opMenu.add(rentItem);
                opMenu.add(delItem);

                /** Array of categories */

                 categories[1]= "1.horror";
                 categories[2]= "2.Sci-fi";
                 categories[3]= "3.Drama";
                 categories[4]= "4.Romance";
                 categories[5]= "5.Comedy";
                 categories[6]= "6.Action";
                 categories[7]= "7.Cartoon";



                /** Setting label */

               area.setBorder(BorderFactory.createLineBorder(Color.RED));

                  /** Main Frame */

                picLabel = new JLabel(new ImageIcon("video.jpg"));



                 newRCombo = new JComboBox(options1);
                 availRCombo  = new JComboBox(options2);
                 nPanel.add(picLabel);

                /** Rent Frame components */

                //rentFrame.add(rentLabelPic);

                instrLabel  =  new JLabel(new ImageIcon("video.jpg"));
                nrthPanel.add(instrLabel);
                areaPanel.add(area3);
                wstPanel.setLayout(new GridLayout(9,1,5,5));
                nrthPanel.setLayout(new FlowLayout());
                sthPanel.setLayout(new  FlowLayout());
                estPanel.setLayout(new GridLayout(1,1));

                instrLabel.setHorizontalAlignment(SwingConstants.CENTER);
                rentFrame.add(nrthPanel,BorderLayout.NORTH);

                wstPanel.add(optionLB);

                wstPanel.add(numLabel);
                wstPanel.add(numField);
                wstPanel.add(tLabel);
                wstPanel.add(titleField);
                rentFrame.add(wstPanel,BorderLayout.WEST);
                sthPanel.add(searcPhone);
                sthPanel.add(searcTitle);
                sthPanel.add(rntBtn);
                sthPanel.add(bckBtn);
                rentFrame.add(sthPanel,BorderLayout.SOUTH);
                //estPanel.add(rentLabelPic);
                rentFrame.add(estPanel,BorderLayout.EAST);
                rentFrame.add(areaPanel,BorderLayout.CENTER);



                /** End of Rent Frame */


                /** Main frame components **/
                northPanel.setLayout(new GridLayout(1,1));
                eastPanel.setLayout(new GridLayout(6,1,12,12));
                westPanel.setLayout(new GridLayout(6,2,12,12));
                southPanel.setLayout(new GridLayout(1,15,9,9));
                mainLabel = new JLabel(new ImageIcon("video.jpg"));


                northPanel.add(mainLabel);
                centerPanel.add(area);

               // pic6Label.setBorder(BorderFactory.createLineBorder(Color.RED));
                pic6Label.setFont(new Font("Tahoma",Font.ITALIC,16));
                centerPanel.add(pic6Label);
                pic6Label.setForeground(Color.RED);
                centerPanel.add(pic7Label);
                Timer timer = new Timer(500, this);
                timer.start();

                addBtn.setIcon(addIcon);
                addBtn.setBorder(BorderFactory.createLineBorder(Color.BLACK));
                delBtn.setIcon(deleteIcon);

                eastPanel.add(addBtn);
                eastPanel.add(delBtn);

                delBtn.setBorder(BorderFactory.createLineBorder(Color.BLACK));
                listBtn.setIcon(sortImg);
                listBtn.setBorder(BorderFactory.createLineBorder(Color.BLACK));
                westPanel.add(listBtn);

                area.setEditable(false);

                southPanel.add(pic2Label);
                southPanel.add(pic3Label);

                southPanel.add(avlBtn);
                avlBtn.setBorder(BorderFactory.createLineBorder(Color.BLACK));
                avlBtn.setIcon(availIcon);
                /** Dummies */


                southPanel.add(exitBtn);
                exitBtn.setIcon(exitIcon);
                exitBtn.setBorder(BorderFactory.createLineBorder(Color.BLACK));

                southPanel.add(pic4Label);
                southPanel.add(pic5Label);

                westPanel.add(custBtn);
                custBtn.setIcon(custIcon);
                custBtn.setBorder(BorderFactory.createLineBorder(Color.BLACK));


                westPanel.add(moviBtn);
                moviBtn.setBorder(BorderFactory.createLineBorder(Color.BLACK));
                moviBtn.setIcon(movieIcon);

                eastPanel.add(rentBtn);
                rentBtn.setBorder(BorderFactory.createLineBorder(Color.BLACK));
                rentBtn.setIcon(rentIcon);


                timeLabel = new JLabel((dateFormat.format(date)));
                timeLabel.setFont(new Font("Serif",Font.ITALIC,16));
                timeLabel.setForeground(Color.RED);
                westPanel.add(timeLabel);

                add(northPanel,BorderLayout.NORTH);
                add(eastPanel,BorderLayout.EAST);
                add(southPanel,BorderLayout.SOUTH);
                add(westPanel,BorderLayout.WEST);
                add(centerPanel,BorderLayout.CENTER);

                /** Setting Layout for Add Frame Panels**/
                nPanel.setLayout(new FlowLayout());
                ePanel.setLayout(new GridLayout(11,1,10,10));
                wPanel.setLayout(new GridLayout(11,1,10,10));
                sPanel.setLayout(new FlowLayout());

                /** Adding Panels on Add Frame Panels */

                catCombo = new JComboBox(categories);

                ePanel.add(movLabel);
                ePanel.add(movRadio);

                wPanel.add(custLabel);
                wPanel.add(custRadio);

                wPanel.add(nameLabel);
                wPanel.add(nameText);
                wPanel.add(snameLabel);
                wPanel.add(snameText);
                wPanel.add(phnLabel);
                wPanel.add(phnText);
                wPanel.add(creditLabel);
                wPanel.add(creditText);

                ePanel.add(titleLabel);
                ePanel.add(titleText);
                ePanel.add(catLabel);
                ePanel.add(catLabel);
                ePanel.add(catCombo);
                ePanel.add(newRLabel);
                ePanel.add(newRCombo);
                ePanel.add(newRCombo);
                ePanel.add(availLabel);
                ePanel.add(availRCombo);
                ePanel.add(insertMBtn);

                wPanel.add(insertCBtn);
                sPanel.add(closeBtn);

                /** Add Frame Panels */
                addFrame.add(nPanel,BorderLayout.NORTH);
                addFrame.add(ePanel,BorderLayout.EAST);
                addFrame.add(sPanel,BorderLayout.SOUTH);
                addFrame.add(wPanel,BorderLayout.WEST);
                addFrame.add(cPanel,BorderLayout.CENTER);
                cPanel.add(area2);


                /** Movies start with.. Panels and Components */

                 fieldPanel.setLayout(new GridLayout(9,1));
                 labelPanel.setLayout(new GridLayout(1,5));
                 startBtnPanel.setLayout(new FlowLayout());
                 strtLabel = new JLabel(new ImageIcon("video.jpg"));

                 labelPanel.add(strtLabel);
                 startAreaPanel.add(startArea);

                 fieldPanel.add(strtFieldLabel);
                 fieldPanel.add(serchField);

                 startBtnPanel.add(startBtn);
                 startBtnPanel.add(gobBtn);

                 startFrame.add(labelPanel,BorderLayout.NORTH);
                 startFrame.add(startAreaPanel,BorderLayout.CENTER);
                 startFrame.add(fieldPanel,BorderLayout.WEST);
                 startFrame.add(startBtnPanel,BorderLayout.SOUTH);

               /** End of Movies Start with */

               /******************************************************************/

               /** Delete Frame Components */

               opPanel.setLayout(new GridLayout(6,1,9,9));
               op2Panel.setLayout(new GridLayout(6,1,9,9));
               topPanel.setLayout(new GridLayout(1,1));
               btnPanel.setLayout(new FlowLayout());

               delPicLabel = new JLabel(new ImageIcon("delMovie.jpg"));
               delLabel= new JLabel(new ImageIcon("video.jpg"));
               topPanel.add(delLabel);
               listPanel.add(delPicLabel);

               //opPanel.add(delLabel);
               opPanel.add(custDelLabel);
               opPanel.add(cutDelText);
               opPanel.add(deleteCBtn);

               op2Panel.add(mvDelLabel);
               op2Panel.add(mvDelText);
               op2Panel.add(deleteMBtn);


               btnPanel.add(toMainBtn);

               delFrame.add(opPanel,BorderLayout.WEST);
               delFrame.add(op2Panel,BorderLayout.EAST);
               delFrame.add(btnPanel,BorderLayout.SOUTH);
               delFrame.add(listPanel,BorderLayout.CENTER);
               delFrame.add(topPanel,BorderLayout.NORTH);

               /** End of delete Components*/

               /** About Programmers Frame **/

               namesPanel.setLayout(new GridLayout(6,1,10,10));
               vidPanel.setLayout(new GridLayout(1,1));

               aboutPic = new JLabel(new ImageIcon("video.jpg"));
               abtPic1Label = new JLabel(new ImageIcon("qiqa.jpg"));
               abtPic2Label = new JLabel(new ImageIcon("joe.jpg"));
               abtPic3Label = new JLabel(new ImageIcon("lynx.jpg"));
               
               vidPanel.add(aboutPic);
               namesPanel.add(qiqaLabel);
               namesPanel.add(abtPic1Label);
               namesPanel.add(joeLabel);
               namesPanel.add(abtPic2Label);
               namesPanel.add(lynxLabel);
               namesPanel.add(abtPic3Label);
               
               proPic = new JLabel(new ImageIcon("programmer.jpg"));
               progPanel.add(proPic);

               aboutFrame.add(namesPanel,BorderLayout.WEST);
               aboutFrame.add(progPanel,BorderLayout.CENTER);
               aboutFrame.add(vidPanel,BorderLayout.NORTH);

               /** End of about programmers Frame*/
               /**Listeners */

                addBtn.addActionListener(this);

                insertCBtn.addActionListener(this);
                insertMBtn.addActionListener(this);
                exitBtn.addActionListener(this);
                closeBtn.addActionListener(this);
                nameText.addActionListener(this);
                snameText.addActionListener(this);
                phnText.addActionListener(this);
                creditText.addActionListener(this);
                custRadio.addActionListener(this);
                movRadio.addActionListener(this);
                custBtn.addActionListener(this);

                rentBtn.addActionListener(this);
                avlBtn.addActionListener(this);
                listBtn.addActionListener(this);
                searcPhone.addActionListener(this);
                searcTitle.addActionListener(this);
                bckBtn.addActionListener(this);
                startBtn.addActionListener(this);
                moviBtn.addActionListener(this);
                gobBtn.addActionListener(this);
                toMainBtn.addActionListener(this);

                addItem.addActionListener(this);
                delItem.addActionListener(this);
                sortMvItem.addActionListener(this);
                custListItem.addActionListener(this);
                rentItem.addActionListener(this);
                exitItem.addActionListener(this);
                avlMvItem.addActionListener(this);
                listMoviItem.addActionListener(this);
                rntBtn.addActionListener(this);
                delBtn.addActionListener(this);
                deleteCBtn.addActionListener(this);
                deleteMBtn.addActionListener(this);

                abtItem.addActionListener(this);

               // area.setBackground(Color.gray);

                /** end of Listeners **/


                /** Hard cording arrays */
                dvdArray[0] = new DVD("Psycho",1,false,true);
                dvdArray[1] = new DVD("Inception",2,true,true);
                dvdArray[2] = new DVD("Godfather",3,false,true);
                dvdArray[3] = new DVD("Valentines day",4,false,true);
                dvdArray[4] = new DVD("Martin",5,false,true);
                dvdArray[5] = new DVD("Safe house",6,true,true);
                dvdArray[6] = new DVD("Spirited way",7,true,true);

                custArray[0] = new Customer("Qiqa","Kotyi","0730051559",100.0);
                custArray[1] = new Customer("Tera","Dyosiba","0745869524",100.0);
                custArray[2] = new Customer("Lynx","Feni","0845512545",100.0);
                custArray[3] = new Customer("Peter","Drake","0793698522",100.0);
                custArray[4] = new Customer("Daymen","Lakay","0856254123",100.0);
                custArray[5] = new Customer("Johan","Botha","0769658441",100.0);
                custArray[6] = new Customer("Ria","McCarthy","089625274",100.0);


            }
    @Override
        public void actionPerformed(ActionEvent e)
        {
                String cred="";
                String newR = "";
                String avlble = "";
                int index =0;
                boolean found = false;
                int f=0; /** for rent btn*/
                int h=0; /** for rent btn*/

                /** Moving Text */
                 String oldText = pic6Label.getText();
                 String newText = oldText.substring(1) + oldText.substring(0, 1);
                 pic6Label.setText( newText );
                 
                 oldText = pic7Label.getText();
                 newText = oldText.substring(1) + oldText.substring(0, 1);
                 pic7Label.setText( newText );

                if((e.getSource()==addBtn) || (e.getSource()==addItem))
                {
                    addFrame.setSize(700,500);
                    addFrame.setVisible(true);

                }
                if(e.getSource()==custRadio){


                    movRadio.setEnabled(false);
                    titleText.setEnabled(false);
                    catCombo.setEnabled(false);
                    newRCombo.setEnabled(false);
                    availRCombo.setEnabled(false);
                }
                else if(e.getSource()==movRadio)
                   {

                    custRadio.setEnabled(false);
                    nameText.setEnabled(false);
                    snameText.setEnabled(false);
                    phnText.setEnabled(false);
                    creditText.setEnabled(false);
                   }
                else if(e.getSource()==insertCBtn){

                  try{
                        firstName=nameText.getText();

                        surname = snameText.getText();
                        phoneNum = phnText.getText();
                        cred= creditText.getText();
                        credit = Double.parseDouble(cred);


                        if(custArray[cnt]==null) {

                             custArray[cnt] = new Customer(firstName,surname,phoneNum,credit);

                          }
                          else
                               JOptionPane.showMessageDialog(null,"The memory is full!!!");
                             
                            
                         if(custArray!=null)
                          {
                           area2.append(custArray[cnt].getName()+"\t"+custArray[cnt].getSurname()+"\t"+custArray[cnt].getPhoneNum()+"\t"+custArray[cnt].getCredit()+"\n");
                          }


                        nameText.setText(null);
                        snameText.setText(null);
                        phnText.setText(null);
                        creditText.setText(null);


                        JOptionPane.showMessageDialog(null,"Your customer has been successfully added!!!");

                           cnt++;
                  }catch(ArrayIndexOutOfBoundsException arrayEx){

                        JOptionPane.showMessageDialog(null,"You can only add 10 customers!!!");
                  }
                    }

                    else if(e.getSource()==insertMBtn){


                        try{

                            title= titleText.getText();
                            category = catCombo.getSelectedIndex();

                            newR = newRCombo.getSelectedItem().toString();
                            newRelease = Boolean.parseBoolean(newR);

                            avlble = availRCombo.getSelectedItem().toString();
                            availableForRent = Boolean.parseBoolean(avlble);

                            if(dvdArray[count]==null)
                            {
                                dvdArray[count] = new DVD(title,category,newRelease,availableForRent);

                            }else
                                JOptionPane.showMessageDialog(null,"The memory is full!!!");

                            if(dvdArray[count]!=null)
                            {
                                area2.append(dvdArray[count].getTitle()+"\t"+dvdArray[count].getCategory()+"\t"+dvdArray[count].isNewRelease()+"\t"+dvdArray[count].isAvailable()+"\n");
                            }

                            titleText.setText(null);


                            JOptionPane.showMessageDialog(null,"Your movie has been successfully added!!!");

                            count++;

                        }catch(ArrayIndexOutOfBoundsException ex){

                            JOptionPane.showMessageDialog(null,"You can only add 10 Movies!!!");
                        }
                }

                if((e.getSource()==custBtn)||(e.getSource()==custListItem))
                {

                 area.setText(null);
                 area.append("SURNAME\t\t"+"NAME\t\t"+"PHONE NUMBER\t"+"CREDIT\n");
                 area.append("------------------------------------------------------------------------------------------------------------------------------------------------\n");

                 int num = 0;
                 for(int b = 0; b < 10 ; b++ )
                 {
                    if(custArray[b] != null)
                        num++;
                 }
                     for(int b = 0; b < 10 ; b++ )
                     {
                           if(custArray[b]!= null)
                            {

                                for(int x = 0 ; x < num ; x++ )
                                {
                                    if(custArray[x].getSurname().compareToIgnoreCase(custArray[b].getSurname())>0)
                                    {
                                        Customer temp = custArray[b];
                                        custArray[b] = custArray[x] ;
                                        custArray[x] = temp ;
                                    }
                                }
                            }
                        }
                        for(int j = 0; j < custArray.length; j++ )
                        {

                            if(custArray[j]!= null)
                            {
                                area.append(custArray[j].getSurname()+"\t\t"+custArray[j].getName()+"\t\t"+custArray[j].getPhoneNum()+"\t\t R"+custArray[j].getCredit()+"\n") ;
                            }
                        }
                }
                if((e.getSource()==listBtn)||(e.getSource()==sortMvItem))
                {

                 area.setText(null);
                 area.append("TITLE\t\t"+"CATEGORY\t\t"+"NEW RELEASE\t\t"+"AVAILABLE\n");
                 area.append("------------------------------------------------------------------------------------------------------------------------------------------------\n");

                 int num = 0;
                 for(int b = 0; b < 10 ; b++ )
                 {
                    if(dvdArray[b] != null)
                        num++;
                 }
                     for(int c= 0; c < 10 ; c++ )
                     {
                           if(dvdArray[c]!= null)
                            {

                                for(int x = 0 ; x < num ; x++ )
                                {
                                    if(dvdArray[x].getTitle().compareToIgnoreCase(dvdArray[c].getTitle())>0)
                                    {
                                        DVD temp = dvdArray[c];
                                        dvdArray[c] = dvdArray[x] ;
                                        dvdArray[x] = temp ;
                                    }
                                }
                            }
                        }
                        for(int j = 0; j < dvdArray.length; j++ )
                        {
                            if(dvdArray[j]!= null)
                            {
                                area.append(dvdArray[j].getTitle()+"\t\t"+dvdArray[j].getCategory()+"\t\t"+dvdArray[j].isNewRelease()+"\t\t"+dvdArray[j].isAvailable()+"\n") ;
                            }
                        }

                }
                if((e.getSource()==avlBtn)||(e.getSource()==avlMvItem))
                {

                 area.setText(null);
                 area.append("TITLE\t\t"+"CATEGORY\t\t"+"NEW RELEASE\t\t"+"AVAILABLE\n");
                 area.append("------------------------------------------------------------------------------------------------------------------------------------------------\n");

                 int number = 0;
                 for(int b = 0; b < 10 ; b++ )
                 {
                    if(dvdArray[b] != null)
                        number++;
                 }
                     for(int c = 0; c < 10 ; c++ )
                     {
                           if(dvdArray[c]!= null)
                            {

                                for(int x = 0 ; x < number ; x++ )
                                {


                                    if(dvdArray[x].getTitle().compareToIgnoreCase(dvdArray[c].getTitle())>0)
                                    {
                                        DVD tempo = dvdArray[c];
                                        dvdArray[c] = dvdArray[x] ;
                                        dvdArray[x] = tempo;
                                    }
                                }
                            }
                        }

                        for(int j = 0; j < dvdArray.length; j++ )
                        {
                            if(dvdArray[j].isAvailable()==true){
                                
                                if(dvdArray[j]!= null)
                            {
                                area.append(dvdArray[j].getTitle()+"\t\t"+dvdArray[j].getCategory()+"\t\t"+dvdArray[j].isNewRelease()+"\t\t"+dvdArray[j].isAvailable()+"\n") ;
                            }
                        }
                       }

                }
                if((e.getSource()==rentBtn)||(e.getSource()==rentItem))
                {
                     rentFrame.setSize(900,500);
                     rentFrame.setVisible(true);
                }

                if((e.getSource() == exitBtn)||(e.getSource()==exitItem))
                {
                    System.exit(0);
                }
                if(e.getSource() == closeBtn)
                {
                    area2.setText(null);

                    movRadio.setEnabled(true);
                    titleText.setEnabled(true);
                    catCombo.setEnabled(true);
                    newRCombo.setEnabled(true);
                    availRCombo.setEnabled(true);

                    custRadio.setEnabled(true);
                    nameText.setEnabled(true);
                    snameText.setEnabled(true);
                    phnText.setEnabled(true);
                    creditText.setEnabled(true);

                    addFrame.dispose();

                }
                if(e.getSource()==abtItem){

                    aboutFrame.setSize(700,600);
                    aboutFrame.setVisible(true);

                }
                if(e.getSource()==searcPhone){

                    try{
                        area3.setText(null);
                        area3.append("SURNAME\t\t"+"NAME\t\t"+"PHONE NUMBER\t"+"CREDIT\n");
                        area3.append("------------------------------------------------------------------------------------------------------------------------------------------------\n");

                        String phoneN = numField.getText();

                        for(int i=0;i<custArray.length;i++){

                            if(phoneN.equals(custArray[i].getPhoneNum())){

                            area3.append(custArray[i].getName()+"\t\t"+custArray[i].getSurname()+"\t\t"+custArray[i].getPhoneNum()+"\t\t"+custArray[i].getCredit()+"\n");
                    }

                   }
                  }catch(Exception ex){

                        System.out.println(""+ex);
                }

                }
                 else
                     if(e.getSource()==searcTitle){


                    try{
                        area3.setText(null);

                        area3.append("TITLE\t\t"+"CATEGORY\t\t"+"NEW RELEASE\t\t"+"AVAILABLE\n");
                        area3.append("------------------------------------------------------------------------------------------------------------------------------------------------\n");

                        String usertitle= titleField.getText();

                        for(int k=0;k<dvdArray.length;k++){

                            if(usertitle.equalsIgnoreCase(dvdArray[k].getTitle())){

                                area3.append(dvdArray[k].getTitle()+"\t\t"+dvdArray[k].getCategory()+"\t\t"+dvdArray[k].isNewRelease()+"\t\t"+dvdArray[k].isAvailable()+"\n");
                           }

                    }
                    }catch(Exception excep){
                    System.out.println(""+excep);
                }
                }
                
                if(e.getSource()==bckBtn){

                   area3.setText(null);
                   numField.setText(null);
                   titleField.setText(null);

                   rentFrame.dispose();
                }
                if((e.getSource()==moviBtn) || (e.getSource()==listMoviItem))
                {


                    startFrame.setSize(700,500);
                    startFrame.setVisible(true);

                }
                if(e.getSource()==startBtn){

                    try{
                    String userSrch = serchField.getText();

                    startArea.setText(null);
                    startArea.append("Your search has returned these results...\n\n\n");
                    startArea.append("TITLE\t\t"+"CATEGORY\t\t"+"NEW RELEASE\t\t"+"AVAILABLE\n");
                    startArea.append("------------------------------------------------------------------------------------------------------------------------------------------------\n");
                    for(int z=0;z<dvdArray.length;z++){

                      if(dvdArray[z].getTitle().startsWith(userSrch)){

                         startArea.append(dvdArray[z].getTitle()+"\t\t"+dvdArray[z].getCategory()+"\t\t"+dvdArray[z].isNewRelease()+"\t\t"+dvdArray[z].isAvailable()+"\n");
                        }

                    }
                    }catch(Exception ef){
                        System.out.println("Cannot find the Movie");
                    }

                }

            if(e.getSource()==gobBtn){


                startArea.setText(null);
                serchField.setText(null);
                startFrame.dispose();

            }
           if((e.getSource()==delBtn)|| (e.getSource()==delItem)){

               delFrame.setSize(500,400);
               delFrame.setVisible(true);

            }
            if(e.getSource()==deleteCBtn){

                String custPhne = cutDelText.getText();
                int i;
                for(int z=0;z<custArray.length;z++)
                {
                if(custArray[z].getPhoneNum().equals(custPhne))
                {

                  found = true;
                  index= z;
                  break;
               }
              }

            if ((found))
                {
                System.out.print(custArray.length);
                for(i=index+1;i<custArray.length;i++)
                {
                    custArray[i - 1]=custArray[i] ;
                }
                custArray[i - 1]= null;
                custCount--;

                JOptionPane.showMessageDialog(null, "Customer deleted!!!");
            }
            else
            {
                JOptionPane.showMessageDialog(null,"Customer phone number was not found !!!");
            }

            }
            if(e.getSource()==delBtn){

               delFrame.setSize(500,400);
               delFrame.setVisible(true);


            }
            if(e.getSource()==deleteMBtn){

                String movTitle = mvDelText.getText();

                int i;
                for(int j=0;j<custArray.length;j++)
                {
                if(dvdArray[j].getTitle().equalsIgnoreCase(movTitle))
                {

                  found = true;
                  index= j;
                  break;
               }

              }

            if ((found))
                {

                for(i=index+1;i<dvdArray.length;i++)
                {
                    dvdArray[i - 1]=dvdArray[i] ;
                }
                dvdArray[i - 1]= null;
                mvCount--;

                JOptionPane.showMessageDialog(null, "Dvd deleted!!!");
            }
            else if(!found)
            {
                JOptionPane.showMessageDialog(null,"DvD title was not found !!!");
            }

            }
            if(e.getSource()==toMainBtn){

                delFrame.dispose();
                cutDelText.setText(null);
                mvDelText.setText(null);

            }
            if(e.getSource()==rntBtn)
            {
                    String movie = titleField.getText();
                    String phone = numField.getText();
                    double cost = 0;
                    Object[] options = {"Yes","No","Cancel"};
                    
                        for(f=0;f<custArray.length;f++){
                            for(h=f;h<dvdArray.length;h++){
                                    if(custArray[f].getPhoneNum().equals(phone)){
                                        if(dvdArray[h].getTitle().equalsIgnoreCase(movie)){
                                            if(dvdArray[h].isNewRelease()==true){
                                                
                                                cost=15;
                                            }
                                            else 
                                                 cost = 10;
                                           
                                            if(custArray[f].getCredit()< 10)
                                                {
                                                    
                                                     int input  = JOptionPane.showOptionDialog(rentFrame,"You have insuficient credit ,would you like to pay cash?","Confirmation Quetion",
                                                     JOptionPane.YES_NO_CANCEL_OPTION,
                                                     JOptionPane.QUESTION_MESSAGE,null,options,options[2]);
                                                     
                                                if(input==JOptionPane.YES_OPTION  ){
                                                
                                                       String amnt =JOptionPane.showInputDialog("Pay R10.00 or  R15.00(only for new DVD)");
                                                       double charge = Double.parseDouble(amnt);
                                                       JOptionPane.showMessageDialog(null,"Thank you for using Mr Video ,enjoy your DVD");
                                                       break;
                                                       
                                                }
                                                else if(input==JOptionPane.NO_OPTION){
                                                    
                                                    break;
                                                
                                                }
                                                else if(input==JOptionPane.CANCEL_OPTION){
                                                    
                                                    JOptionPane.showMessageDialog(null,"Transaction Cancelled!!!");
                                                    break;
                                                    }
                                            }
                                            else {
                                                JOptionPane.showMessageDialog(null,"Thank you for using Mr Video, Enjoy your DVD!!!");
                                            }
                                            total1 = custArray[f].getCredit()-cost;
                                            custArray[f].setCredit(total1);
                                            dvdArray[h].setAvailable(false);
                                           
                                       
                          }
                         }
                         }
                        }
                        
                     }
        }
}